package java8;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @program: util
 * @description:
 * @author: zhouliangliang
 * @create: 2020-02-24 22:47
 **/
public class TestToMap {

    public void test(Persion ...persions) {
        Map<String, String> map = Arrays.asList(persions).stream().collect(Collectors.toMap(Persion::getName, Persion::getAddress, (s, a) -> s+","+a));

        for(Map.Entry entry : map.entrySet()) {
            System.out.println(entry.getKey());
            System.out.println(entry.getValue());
        }
    }

    public static void main(String[] args) {
        Persion p1 = new Persion("zhouliangliang", "address");
        Persion p2 = new Persion("zhouliangliang1", "address1");
        Persion p3 = new Persion("zhouliangliang", "address2");
        new TestToMap().test(p1,p2,p3);
    }


    static class Persion{
        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        private String name;
        private String address;

        public Persion(String name, String address) {
            this.name = name;
            this.address = address;
        }
    }
}
